<?php
if (!isset($GLOBALS['objDB'])){
	$GLOBALS['objDB'] = AdodbConn(); 
}
if (!isset($GLOBALS['objMDB2'])){
	$GLOBALS['objMDB2'] = MDB2Conn();
}

if (!isset($GLOBALS['objMail'])) {
	$GLOBALS['objMAIL'] = MailConn();	
}

	function AdodbConn(){
		
	    require $GLOBALS['arrCfg']['strPhysicalPath']."lib/adodb/adodb.inc.php";
	    $objDb = ADONewConnection($GLOBALS['arrCfg']['strAdodbDriver']);
	    $objDb->debug = false;
	    $objDb->Connect($GLOBALS['arrCfg']['strDbHost'], $GLOBALS['arrCfg']['strDbUser'], $GLOBALS['arrCfg']['strDbPass'], $GLOBALS['arrCfg']['strDbName']);
		if ($objDb->ErrorMsg()) print "ADODB ERROR: ".$objDb->ErrorMsg();
	    $ADODB_FETCH_MODE = ADODB_FETCH_BOTH;
		return $objDb;
    }
    
    function MDB2Conn(){
    	// MDB2 config
		require 'MDB2.php';
		$dsn = array(
		    'phptype'  => $GLOBALS['arrCfg']['strAdodbDriver'],
		    'username' => $GLOBALS['arrCfg']['strDbUser'],
		    'password' => $GLOBALS['arrCfg']['strDbPass'],
		    'hostspec' => $GLOBALS['arrCfg']['strDbHost'],
		    'database' => $GLOBALS['arrCfg']['strDbName'],
		);
	
		$options = array(
		    'debug'       => 2,
		    'portability' => MDB2_PORTABILITY_ALL,
		);
	
		// uses MDB2::factory() to create the instance
		// and also attempts to connect to the host
		$mdb2 =& MDB2::connect($dsn, $options);
		if (PEAR::isError($mdb2)) {
			//    die($mdb2->getMessage());
			echo "Error accour when connecting to database with MDB2 pear package !";
		}
    	return $mdb2;
    }
    
    function MailConn() {
  		require 'Mail.php';
  		$params['debug'] = FALSE;
  		// Create the mail object using the Mail::factory method
		$mail_object =& Mail::factory('smtp', $params);
		return $mail_object;
    }
?>